namespace SimpleWebServices.Models
{
    using System.Globalization;
    using System.Xml.Serialization;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web;

    /// http://en.wikipedia.org/wiki/ISO_4217
    [XmlRoot("currency")]
    public sealed class Currency : Resource
    {
        [XmlAttribute("code")]
        public string Code
        {
            get;
            set;
        }

        [XmlIgnore]
        public override string Entity
        {
            get
            {
                Entity value = new Entity(base.Entity);
                value.Append(this.Code);
                value.Append(this.Number);
                value.Append(this.Significance);
                value.Append(this.Symbol);

                return value;
            }
        }

        [XmlAttribute("number")]
        public string Number
        {
            get;
            set;
        }

        [XmlAttribute("significance")]
        public int Significance
        {
            get;
            set;
        }

        [XmlAttribute("symbol")]
        public string Symbol
        {
            get;
            set;
        }

        public NumberFormatInfo ToNumberFormatInfo()
        {
            NumberFormatInfo result = (NumberFormatInfo)CultureInfo.CurrentUICulture.NumberFormat.Clone();
            result.CurrencyDecimalDigits = this.Significance;
            result.CurrencySymbol = this.Symbol;

            return result;
        }
    }
}